<!doctype html>
<html class="no-js" lang="en, zh-CN" data-content_root="../../">
  <head><meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<link rel="index" title="Index" href="../../genindex.html" /><link rel="search" title="Search" href="../../search.html" /><link rel="next" title="Know the Lock" href="lock.html" /><link rel="prev" title="Resource Management" href="index.html" />

    <link rel="shortcut icon" href="../../_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 -->
        <title>Load and Unload - Javet 3.0.0 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=a746c00c" />
    <link rel="stylesheet" type="text/css" href="../../_static/styles/furo.css?v=135e06be" />
    <link rel="stylesheet" type="text/css" href="../../_static/tabs.css?v=4c969af8" />
    <link rel="stylesheet" type="text/css" href="../../_static/styles/furo-extensions.css?v=36a5483c" />
    <link rel="stylesheet" type="text/css" href="../../_static/css/custom.css?v=c2631171" />
    
    


<style>
  body {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  @media not print {
    body[data-theme="dark"] {
      --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
    }
    @media (prefers-color-scheme: dark) {
      body:not([data-theme="light"]) {
        --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
      }
    }
  }
</style></head>
  <body>
    
    <script>
      document.body.dataset.theme = localStorage.getItem("theme") || "auto";
    </script>
    

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
      <path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
  <symbol id="svg-sun" viewBox="0 0 24 24">
    <title>Light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
      <circle cx="12" cy="12" r="5"></circle>
      <line x1="12" y1="1" x2="12" y2="3"></line>
      <line x1="12" y1="21" x2="12" y2="23"></line>
      <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
      <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
      <line x1="1" y1="12" x2="3" y2="12"></line>
      <line x1="21" y1="12" x2="23" y2="12"></line>
      <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
      <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
    </svg>
  </symbol>
  <symbol id="svg-moon" viewBox="0 0 24 24">
    <title>Dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
    </svg>
  </symbol>
  <symbol id="svg-sun-half" viewBox="0 0 24 24">
    <title>Auto light/dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
      <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
      <circle cx="12" cy="12" r="9" />
      <path d="M13 12h5" />
      <path d="M13 15h4" />
      <path d="M13 18h1" />
      <path d="M13 9h4" />
      <path d="M13 6h1" />
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
  <div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
  <div class="visually-hidden">Hide table of contents sidebar</div>
</label>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <div class="visually-hidden">Toggle site navigation sidebar</div>
        <i class="icon"><svg><use href="#svg-menu"></use></svg></i>
      </label>
    </div>
    <div class="header-center">
      <a href="../../index.html"><div class="brand">Javet 3.0.0 documentation</div></a>
    </div>
    <div class="header-right">
      <div class="theme-toggle-container theme-toggle-header">
        <button class="theme-toggle">
          <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
          <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
          <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
          <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
        </button>
      </div>
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <div class="visually-hidden">Toggle table of contents sidebar</div>
        <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand" href="../../index.html">
  
  <div class="sidebar-logo-container">
    <img class="sidebar-logo" src="../../_static/logo.png" alt="Logo"/>
  </div>
  
  <span class="sidebar-brand-text">Javet 3.0.0 documentation</span>
  
</a><form class="sidebar-search-container" method="get" action="../../search.html" role="search">
  <input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
  <ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="../../tutorial/index.html">Tutorial</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Tutorial</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/basic/index.html">Basic</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of Basic</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/installation.html">Installation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/hello_javet.html">Hello Javet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/javet_shell.html">Javet Shell</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/interception.html">Interception</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/engine_pool.html">Javet Engine Pool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/node_js_mode_and_v8_mode.html">Node.js Mode and V8 Mode</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/spring_integration.html">Spring Integration</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/basic/polyfill.html">Polyfill</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/advanced/index.html">Advanced</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of Advanced</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/interact_with_node_js.html">Interact with Node.js</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/java_and_javascript_interop.html">Java and JavaScript Interop</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/advanced/expose_json_node_in_v8.html">Expose JsonNode in V8</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../tutorial/migration_guides/index.html">Migration Guides</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle navigation of Migration Guides</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../tutorial/migration_guides/migrate_from_j2v8.html">Migrate from J2V8</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="../index.html">Reference</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle navigation of Reference</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../javadoc/index.html">API Reference</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../v8_values/index.html">V8 Values</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle navigation of V8 Values</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_collection.html">V8 Collection</a></li>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_function.html">V8 Function</a></li>
<li class="toctree-l3"><a class="reference internal" href="../v8_values/v8_promise.html">V8 Promise</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../converters/index.html">Converters</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle navigation of Converters</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../converters/primitive_converter.html">Primitive Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/proxy_converter.html">Proxy Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/bridge_converter.html">Bridge Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../converters/custom_converter.html">Custom Converter</a></li>
</ul>
</li>
<li class="toctree-l2 current has-children"><a class="reference internal" href="index.html">Resource Management</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle navigation of Resource Management</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l3 current current-page"><a class="current reference internal" href="#">Load and Unload</a></li>
<li class="toctree-l3"><a class="reference internal" href="lock.html">Know the Lock</a></li>
<li class="toctree-l3"><a class="reference internal" href="memory_management.html">Memory Management</a></li>
<li class="toctree-l3"><a class="reference internal" href="modularization.html">Modularization</a></li>
<li class="toctree-l3"><a class="reference internal" href="performance.html">Javet Performance</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/error_codes.html">Error Codes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/logging.html">Logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/termination.html">Termination</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../tips/index.html">Tips</a><input class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><div class="visually-hidden">Toggle navigation of Tips</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../tips/best_practices.html">Best Practices</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../todo_list.html">TODO List</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../release_notes/index.html">Release Notes</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><div class="visually-hidden">Toggle navigation of Release Notes</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../../release_notes/release_notes_3_0.html">Release Notes 3.0.x</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../faq/index.html">FAQ</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" role="switch" type="checkbox"/><label for="toctree-checkbox-12"><div class="visually-hidden">Toggle navigation of FAQ</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/background/index.html">Background</a><input class="toctree-checkbox" id="toctree-checkbox-13" name="toctree-checkbox-13" role="switch" type="checkbox"/><label for="toctree-checkbox-13"><div class="visually-hidden">Toggle navigation of Background</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/background/history_with_j2v8.html">History with J2V8</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/background/what_is_the_motivation.html">What is the Motivation?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-14" name="toctree-checkbox-14" role="switch" type="checkbox"/><label for="toctree-checkbox-14"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/how_to_think_in_javet.html">How to Think in Javet?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/where_are_es6_api_in_v8_mode.html">Where are ES6 API in V8 Mode?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/where_are_the_examples.html">Where are the Examples?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/development/why_is_the_inspector_disabled_in_node_js_mode.html">Why is the Inspector Disabled in Node.js Mode?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/environment/index.html">Environment</a><input class="toctree-checkbox" id="toctree-checkbox-15" name="toctree-checkbox-15" role="switch" type="checkbox"/><label for="toctree-checkbox-15"><div class="visually-hidden">Toggle navigation of Environment</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/environment/can_javet_support_legacy_linux.html">Can Javet Support Legacy Linux?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../faq/troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-16" name="toctree-checkbox-16" role="switch" type="checkbox"/><label for="toctree-checkbox-16"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/a_dynamic_link_library_dll_initialization_routine_failed.html">A dynamic link library (DLL) initialization routine failed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/can_i18n_be_supported.html">Can i18n be Supported?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/can_i_debug_javet_in_chrome_dev_tools.html">Can I Debug Javet in Chrome DevTools?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../faq/troubleshooting/why_node_js_crashes_when_being_closed.html">Why Node.js Crashes When being Closed?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../../development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-17" name="toctree-checkbox-17" role="switch" type="checkbox"/><label for="toctree-checkbox-17"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../../development/tools.html">Development Tools</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../../development/build.html">Build Javet</a><input class="toctree-checkbox" id="toctree-checkbox-18" name="toctree-checkbox-18" role="switch" type="checkbox"/><label for="toctree-checkbox-18"><div class="visually-hidden">Toggle navigation of Build Javet</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../../development/build_javet_with_docker.html">Build Javet with Docker</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../development/build_javet_from_scratch.html">Build Javet from Scratch</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../development/test.html">Test Javet</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/design.html">Javet Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/performance.html">Javet Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../development/debug_with_chrome_developer_tools.html">Debug with Chrome Developer Tools</a></li>
</ul>
</li>
</ul>

</div>
</div>

      </div>
      
    </div>
  </aside>
  <div class="main">
    <div class="content">
      <div class="article-container">
        <a href="#" class="back-to-top muted-link">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
          </svg>
          <span>Back to top</span>
        </a>
        <div class="content-icon-container">
          
<div class="theme-toggle-container theme-toggle-content">
            <button class="theme-toggle">
              <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
              <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
              <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
              <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
            </button>
          </div>
          <label class="toc-overlay-icon toc-content-icon" for="__toc">
            <div class="visually-hidden">Toggle table of contents sidebar</div>
            <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
          </label>
        </div>
        <article role="main">
          <section id="load-and-unload">
<h1>Load and Unload<a class="headerlink" href="#load-and-unload" title="Link to this heading">#</a></h1>
<p>As documented in <a class="reference internal" href="../../development/design.html"><span class="doc">Javet Design</span></a>, Javet supports loading and unloading the JNI libraries during runtime in both Node.js and V8 modes.</p>
<section id="can-javet-native-library-be-loaded-or-unloaded-on-demand">
<h2>Can Javet Native Library be Loaded or Unloaded On-demand?<a class="headerlink" href="#can-javet-native-library-be-loaded-or-unloaded-on-demand" title="Link to this heading">#</a></h2>
<p>Yes, Javet supports that.</p>
<section id="unload">
<h3>Unload<a class="headerlink" href="#unload" title="Link to this heading">#</a></h3>
<p>Assuming the JNI library per mode is already loaded, here are the step-by-step on how to unload it.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Step 1: Set library reloadable. Why? Because Javet defaults that switch to false.</span>
<span class="n">V8Host</span><span class="p">.</span><span class="na">setLibraryReloadable</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<span class="c1">// Step 2: Get V8Host per JS runtime type.</span>
<span class="n">V8Host</span><span class="w"> </span><span class="n">v8Host</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">V8Host</span><span class="p">.</span><span class="na">getInstance</span><span class="p">(</span><span class="n">jsRuntimeType</span><span class="p">);</span>
<span class="c1">// Step 3: Unload the library.</span>
<span class="n">v8Host</span><span class="p">.</span><span class="na">unloadLibrary</span><span class="p">();</span>
<span class="c1">// Step 4: Restore the switch.</span>
<span class="n">V8Host</span><span class="p">.</span><span class="na">setLibraryReloadable</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span>
</pre></div>
</div>
<p>How does <code class="docutils literal notranslate"><span class="pre">unloadLibrary()</span></code> work? There is no API that allows unloading a JNI library explicitly. The only way is GC will automatically unload the library if all references to that library are garbage collectable. So, application is supposed to close all V8 values, V8 runtimes prior to calling <code class="docutils literal notranslate"><span class="pre">unloadLibrary()</span></code>.</p>
</section>
<section id="load">
<h3>Load<a class="headerlink" href="#load" title="Link to this heading">#</a></h3>
<p>Assuming the JNI library per mode is already unloaded, here are the step-by-step on how to load it again.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Step 1: Get V8Host per JS runtime type.</span>
<span class="n">V8Host</span><span class="w"> </span><span class="n">v8Host</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">V8Host</span><span class="p">.</span><span class="na">getInstance</span><span class="p">(</span><span class="n">jsRuntimeType</span><span class="p">);</span>
<span class="c1">// Step 2: Load the library.</span>
<span class="n">v8Host</span><span class="p">.</span><span class="na">loadLibrary</span><span class="p">();</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">unloadLibrary()</span></code> can only take effect after all references are garbage collectable.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">loadLibrary()</span></code> is internally called by Javet at the first time and only takes effect after <code class="docutils literal notranslate"><span class="pre">unloadLibrary()</span></code> is called.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">loadLibrary()</span></code> and <code class="docutils literal notranslate"><span class="pre">unloadLibrary()</span></code> are for experiment only. <strong>They may be unstable and crash JVM. Please use this feature at your own risk.</strong></p></li>
</ul>
</div>
</section>
</section>
<section id="can-javet-native-library-be-deployed-to-a-custom-location">
<h2>Can Javet Native Library be Deployed to a Custom Location?<a class="headerlink" href="#can-javet-native-library-be-deployed-to-a-custom-location" title="Link to this heading">#</a></h2>
<p>Yes. By default, the native library is deployed to system temp which might not be accessible in some cases. Here is a simple way of telling Javet where to deploy the library.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">JavetLibLoader</span><span class="p">.</span><span class="na">setLibLoadingListener</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">IJavetLibLoadingListener</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">File</span><span class="w"> </span><span class="nf">getLibPath</span><span class="p">(</span><span class="n">JSRuntimeType</span><span class="w"> </span><span class="n">jsRuntimeType</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">File</span><span class="p">(</span><span class="s">&quot;/../anywhere&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">});</span>
</pre></div>
</div>
<p>By default, the native library is deployed by Javet. To bypass the deployment, one more function is required to be overridden. That also means the applications are responsible for deploying the native library to the right location.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">JavetLibLoader</span><span class="p">.</span><span class="na">setLibLoadingListener</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">IJavetLibLoadingListener</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">File</span><span class="w"> </span><span class="nf">getLibPath</span><span class="p">(</span><span class="n">JSRuntimeType</span><span class="w"> </span><span class="n">jsRuntimeType</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">File</span><span class="p">(</span><span class="s">&quot;/../anywhere&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>

<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kt">boolean</span><span class="w"> </span><span class="nf">isDeploy</span><span class="p">(</span><span class="n">JSRuntimeType</span><span class="w"> </span><span class="n">jsRuntimeType</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">});</span>
</pre></div>
</div>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">JavetLibLoader.setLibLoadingListener()</span></code> must be called before <code class="docutils literal notranslate"><span class="pre">V8Host</span></code> is called, otherwise it won't take effect.</p></li>
<li><p>The return path from <code class="docutils literal notranslate"><span class="pre">getLibPath()</span></code> does not include the library file name because Javet will prepare it.</p></li>
</ul>
</div>
</section>
<section id="can-javet-native-library-deployment-be-skipped">
<h2>Can Javet Native Library Deployment be Skipped?<a class="headerlink" href="#can-javet-native-library-deployment-be-skipped" title="Link to this heading">#</a></h2>
<p>Yes. In some cases, the native library can be directly deployed to system library path to avoid dynamic deployment. That brings better performance and less jar file size. Here is a sample way of telling Javet to skip the deployment.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">JavetLibLoader</span><span class="p">.</span><span class="na">setLibLoadingListener</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">IJavetLibLoadingListener</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="nf">isLibInSystemPath</span><span class="p">(</span><span class="n">JSRuntimeType</span><span class="w"> </span><span class="n">jsRuntimeType</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">});</span>
</pre></div>
</div>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p><code class="docutils literal notranslate"><span class="pre">JavetLibLoader.setLibLoadingListener()</span></code> must be called before <code class="docutils literal notranslate"><span class="pre">V8Host</span></code> is called, otherwise it won't take effect.</p>
</div>
</section>
<section id="can-already-loaded-in-another-classloader-be-suppressed">
<h2>Can <em>already loaded in another classloader</em> be Suppressed?<a class="headerlink" href="#can-already-loaded-in-another-classloader-be-suppressed" title="Link to this heading">#</a></h2>
<p>In some cases, the applications are hosted by some other classloaders (e.g. Mavin plug-in host, Osgi, etc.) that actively load and unload the applications on demand. That causes the Javet native library to be loaded repeatedly. However, JVM only allows one memory copy of a particular JNI library regardless of at which classloader it stays.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">java</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">UnsatisfiedLinkError</span><span class="p">:</span> <span class="n">Native</span> <span class="n">Library</span> <span class="o">***</span><span class="n">libjavet</span><span class="o">***</span> <span class="n">already</span> <span class="n">loaded</span> <span class="ow">in</span> <span class="n">another</span> <span class="n">classloader</span>
</pre></div>
</div>
<p>By default, Javet treats that as an error and prevent all API from working. But, applications may want to suppress this error because the Javet native library has already been loaded. Yes, Javet allows that. Here is a sample.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">JavetLibLoader</span><span class="p">.</span><span class="na">setLibLoadingListener</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">IJavetLibLoadingListener</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="nd">@Override</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="nf">isSuppressingError</span><span class="p">(</span><span class="n">JSRuntimeType</span><span class="w"> </span><span class="n">jsRuntimeType</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">});</span>
</pre></div>
</div>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p><code class="docutils literal notranslate"><span class="pre">JavetLibLoader.setLibLoadingListener()</span></code> must be called before <code class="docutils literal notranslate"><span class="pre">V8Host</span></code> is called, otherwise it won't take effect.</p>
</div>
</section>
<section id="can-javet-lib-loading-listener-take-environment-variables">
<h2>Can Javet Lib Loading Listener Take Environment Variables?<a class="headerlink" href="#can-javet-lib-loading-listener-take-environment-variables" title="Link to this heading">#</a></h2>
<p>Yes. In some cases, it is inconvenient to inject a listener. No worry, <code class="docutils literal notranslate"><span class="pre">JavetLibLoadingListener</span></code> can take <code class="docutils literal notranslate"><span class="pre">javet.lib.loading.path</span></code>,  <code class="docutils literal notranslate"><span class="pre">javet.lib.loading.type</span></code> and <code class="docutils literal notranslate"><span class="pre">javet.lib.loading.suppress.error</span></code> so that applications can inject custom lib loading mechanism without implementing a new listener.</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># Load the Javet library from /abc with auto-deployment</span>
java<span class="w"> </span>...<span class="w"> </span>-Djavet.lib.loading.path<span class="o">=</span>/abc

<span class="c1"># Load the Javet library from /abc without auto-deployment</span>
java<span class="w"> </span>...<span class="w"> </span>-Djavet.lib.loading.path<span class="o">=</span>/abc<span class="w"> </span>-Djavet.lib.loading.type<span class="o">=</span>custom

<span class="c1"># Load the Javet library from system library path</span>
java<span class="w"> </span>...<span class="w"> </span>-Djavet.lib.loading.type<span class="o">=</span>system

<span class="c1"># Suppress the error in loading the library</span>
java<span class="w"> </span>...<span class="w"> </span>-Djavet.lib.loading.suppress.error<span class="o">=</span><span class="nb">true</span>
</pre></div>
</div>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>This doesn't apply to Android.</p>
</div>
</section>
<section id="can-javet-libraries-be-removed-from-the-jar-file">
<h2>Can Javet Libraries be Removed from the Jar File?<a class="headerlink" href="#can-javet-libraries-be-removed-from-the-jar-file" title="Link to this heading">#</a></h2>
<p>Yes, <code class="docutils literal notranslate"><span class="pre">javet-core</span></code> is available without the libraries. Just update <code class="docutils literal notranslate"><span class="pre">javet</span></code> or <code class="docutils literal notranslate"><span class="pre">javet-macos</span></code> to <code class="docutils literal notranslate"><span class="pre">javet-core</span></code> in the <a class="reference internal" href="../../tutorial/basic/installation.html"><span class="doc">Installation</span></a>.</p>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>This doesn't apply to Android.</p>
</div>
</section>
</section>

        </article>
      </div>
      <footer>
        
        <div class="related-pages">
          <a class="next-page" href="lock.html">
              <div class="page-info">
                <div class="context">
                  <span>Next</span>
                </div>
                <div class="title">Know the Lock</div>
              </div>
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
            </a>
          <a class="prev-page" href="index.html">
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
              <div class="page-info">
                <div class="context">
                  <span>Previous</span>
                </div>
                
                <div class="title">Resource Management</div>
                
              </div>
            </a>
        </div>
        <div class="bottom-of-page">
          <div class="left-details">
            <div class="copyright">
                Copyright &#169; 2021-2023. caoccao.com Sam Cao
            </div>
            Made with 
            <a href="https://github.com/pradyunsg/furo">Furo</a>
            
          </div>
          <div class="right-details">
            
          </div>
        </div>
        
      </footer>
    </div>
    <aside class="toc-drawer">
      
      
      <div class="toc-sticky toc-scroll">
        <div class="toc-title-container">
          <span class="toc-title">
            On this page
          </span>
        </div>
        <div class="toc-tree-container">
          <div class="toc-tree">
            <ul>
<li><a class="reference internal" href="#">Load and Unload</a><ul>
<li><a class="reference internal" href="#can-javet-native-library-be-loaded-or-unloaded-on-demand">Can Javet Native Library be Loaded or Unloaded On-demand?</a><ul>
<li><a class="reference internal" href="#unload">Unload</a></li>
<li><a class="reference internal" href="#load">Load</a></li>
</ul>
</li>
<li><a class="reference internal" href="#can-javet-native-library-be-deployed-to-a-custom-location">Can Javet Native Library be Deployed to a Custom Location?</a></li>
<li><a class="reference internal" href="#can-javet-native-library-deployment-be-skipped">Can Javet Native Library Deployment be Skipped?</a></li>
<li><a class="reference internal" href="#can-already-loaded-in-another-classloader-be-suppressed">Can <em>already loaded in another classloader</em> be Suppressed?</a></li>
<li><a class="reference internal" href="#can-javet-lib-loading-listener-take-environment-variables">Can Javet Lib Loading Listener Take Environment Variables?</a></li>
<li><a class="reference internal" href="#can-javet-libraries-be-removed-from-the-jar-file">Can Javet Libraries be Removed from the Jar File?</a></li>
</ul>
</li>
</ul>

          </div>
        </div>
      </div>
      
      
    </aside>
  </div>
</div><script src="../../_static/documentation_options.js?v=5e0dd536"></script>
    <script src="../../_static/doctools.js?v=888ff710"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/scripts/furo.js?v=32e29ea5"></script>
    <script src="../../_static/tabs.js?v=3ee01567"></script>
    </body>
</html>